package com.agrm.rabc.service.impl;

import com.agrm.model.rabc.dto.Group;
import com.agrm.rabc.mapper.GroupDao;
import com.agrm.rabc.service.GroupService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@CacheConfig(cacheNames = "c.s.r.s.impl.GroupServiceImpl")
@Service
public class GroupServiceImpl implements GroupService {
    private GroupDao groupDao;

    @Autowired
    public void setGroupDao(GroupDao groupDao) {
        this.groupDao = groupDao;
    }

    //无缓存，因为有查询条件和分页
    @Override
    public Page<Group> findAll(Group group, Page<Group> page) {
        return groupDao.findAll(group, page);
    }

    @Cacheable(key = "#p0")
    @Override
    public Group findById(Integer id) {
        return groupDao.selectById(id);
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean save(Group group) {
        return groupDao.insert(group) == 1;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean update(Group group) {
        return groupDao.updateById(group) == 1;
    }

    @CacheEvict(allEntries = true)
    @Override
    public int deleteByIds(List<Integer> ids) {
        return groupDao.deleteByIds(ids);
    }
}
